| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var chai = require('chai') |
||
| 11 | describe('Test Email API', function () { |
||
| 12 | it('it should send an email', function (done) { |
||
| 13 | var transportStub = { |
||
| 14 | sendMail: function (options) { |
||
|
|
|||
| 15 | return new Promise((resolve, reject) => { resolve(true, false) }) |
||
| 16 | } |
||
| 17 | } |
||
| 18 | |||
| 19 | var sendMailSpy = sinon.spy(transportStub, 'sendMail') |
||
| 20 | var mailerStub = sinon.stub(nodemailer, 'createTransport').returns(transportStub) |
||
| 21 | |||
| 22 | var mail = { |
||
| 23 | to: '[email protected]', |
||
| 24 | subject: 'Hello ✔', |
||
| 25 | text: 'Hello world 🐴', |
||
| 26 | html: '<b>Hello world 🐴</b>' |
||
| 27 | } |
||
| 28 | chai.request(server) |
||
| 29 | .post(prefix + '/email') |
||
| 30 | .send(mail) |
||
| 31 | .end(function (err, res) { |
||
| 32 | should.not.exist(err) |
||
| 33 | res.should.have.status(200) |
||
| 34 | res.body.should.be.a('object') |
||
| 35 | res.body.should.have.property('message').eql('Message sent') |
||
| 36 | mailerStub.restore() |
||
| 37 | done() |
||
| 38 | }) |
||
| 39 | }) |
||
| 40 | |||
| 41 | it('it should send an email', function (done) { |
||
| 42 | var transportStub = { |
||
| 43 | sendMail: function (options) { |
||
| 44 | return new Promise((resolve, reject) => { reject(new Error('Something went wrong with mail service')) }) |
||
| 45 | } |
||
| 46 | } |
||
| 47 | var sendMailSpy = sinon.spy(transportStub, 'sendMail') |
||
| 48 | var mailerStub = sinon.stub(nodemailer, 'createTransport').returns(transportStub) |
||
| 49 | |||
| 50 | var mail = { |
||
| 51 | to: '[email protected]', |
||
| 52 | subject: 'Hello ✔', |
||
| 53 | text: 'Hello world 🐴', |
||
| 54 | html: '<b>Hello world 🐴</b>' |
||
| 55 | } |
||
| 56 | chai.request(server) |
||
| 57 | .post(prefix + '/email') |
||
| 58 | .send(mail) |
||
| 59 | .end(function (err, res) { |
||
| 60 | //should.exist(err) |
||
| 61 | res.should.have.status(404) |
||
| 62 | res.body.should.be.a('object') |
||
| 63 | err.should.have.property('message').eql('Not Found') |
||
| 64 | mailerStub.restore() |
||
| 65 | done() |
||
| 66 | }) |
||
| 67 | }) |
||
| 68 | }) |
||
| 69 | |||
| 137 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.